package com.group3.controller.studentController;

import com.group3.domain.Leave;
import com.group3.pojo.receive.LeaveReceive;
import com.group3.service.StudentLeaveService;
import com.group3.utils.Result;
import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Api(tags = "学生接口")
@RestController
@RequestMapping("/student/leave")
@CrossOrigin
public class StudentLeaveController {
    @Resource
    private StudentLeaveService studentLeaveService;

    @GetMapping(value = "/leaveRecord")
    @ApiOperation(value = "根据学生id查询学生个人请假记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "studentId", value = "学生id",
                    dataType = "String",required = true),
            @ApiImplicitParam(name = "leaveTheme", value = "请假主题",
                    dataType = "String"),
            @ApiImplicitParam(name = "startTime", value = "提交时间段开始",
                    dataType = "String"),
            @ApiImplicitParam(name = "endTime", value = "提交时间段结束",
                    dataType = "String"),
            @ApiImplicitParam(name = "type", value = "请假类型（请假原因）",
                    dataType = "String"),
            @ApiImplicitParam(name = "state", value = "审批状态",
                    dataType = "Integer"),
    })
    public Result<List<Leave>> getLeaveRecord(LeaveReceive leaveReceive){

        Result result = studentLeaveService.getLeaveRecord(leaveReceive);

        return result;
    }

    @GetMapping(value = "/getLeaveDetail")
    @ApiOperation(value = "查询请假详情，点击编辑、详情时的显示页面")
    @ApiImplicitParam(name = "leaveId", value = "请假id",required = true,
            dataType = "String")
    //todo 查询请假详情响应参数
    public Result getLeaveDetail(String leaveId){

        Result result = studentLeaveService.getLeaveDetail(leaveId);
        return result;
    }

    @PostMapping(value = "/submitLeave"  )
    @ApiOperation(value = "提交请假申请"  )
    @ApiImplicitParams({
            @ApiImplicitParam(name = "theme", value = "请假主题",
                    dataType = "String",required = true),
            @ApiImplicitParam(name = "reason", value = "原因说明",
                    dataType = "String",required = true),
            @ApiImplicitParam(name = "startTime", value = "请假开始时间",
                    dataType = "Date",required = true),
            @ApiImplicitParam(name = "endTime", value = "请假结束时间",
                    dataType = "Date",required = true),
            @ApiImplicitParam(name = "type", value = "请假类型（原因）",
                    dataType = "String",required = true),
    })
    public Result submitLeave(HttpServletRequest request, @RequestBody Leave leave){

        String token = request.getHeader("token");//获取token
        Result result = studentLeaveService.submitLeave(leave,token);

        return result;
    };

    @PostMapping(value = "/redoLeave"  )
    @ApiOperation(value = "重新提交请假申请（修改）"  )
    @ApiImplicitParams({
            @ApiImplicitParam(name = "leaveId", value = "请假id",
                    dataType = "String",required = true),
            @ApiImplicitParam(name = "leaveTheme", value = "请假主题",
                    dataType = "String",required = true),
            @ApiImplicitParam(name = "reason", value = "请假原因",
                    dataType = "String",required = true),
            @ApiImplicitParam(name = "startTime", value = "请假开始时间",
                    dataType = "Date",required = true),
            @ApiImplicitParam(name = "endTime", value = "请假结束时间",
                    dataType = "Date",required = true),
            @ApiImplicitParam(name = "type", value = "请假类型",
                    dataType = "String"),
    })
    public Result redoLeave(HttpServletRequest request, @RequestBody Leave leave){

        String token = request.getHeader("token");//获取token
        Result result = studentLeaveService.redoLeave(leave,token);

        return result;
    }
}
